package com.athl.demoreactor;

import com.athl.demoreactor.entity.User;
import org.springframework.http.MediaType;
import org.springframework.web.reactive.function.client.WebClient;
import reactor.core.publisher.Flux;

import java.util.List;

/**
 * @author hl
 * @Data 2020/9/16
 */
public class Client {

    public static void main(String[] args) {
        // 调用服务器地址
        WebClient webClient = WebClient.create("http://127.0.0.1:12560");

        // 根据id查询
        String id = "1";
        User userMono = webClient.get().uri("user/{id}", id).accept(MediaType.APPLICATION_JSON).retrieve().bodyToMono(User.class).block();
        System.out.println(userMono.toString());

        Flux<User> userFlux = webClient.get().uri("/users").accept(MediaType.APPLICATION_JSON).retrieve().bodyToFlux(User.class);
        List<User> users = userFlux.buffer().blockFirst();
        for (User user : users) {
            System.out.println(user);
        }
    }
}
